import { useModel } from "umi";
import { useReactive } from "ahooks";

const userGatewayRegister = () => {
    const { remoteData } = useModel("global");

    const state = useReactive({
        loading: false,
    });

    const personGatewayRegister = async (gatewayInfo, baseInfo, callback) => {
        if (!gatewayInfo.url) return;
        state.loading = true;
        let res = await remoteData({
            object: "multi-person-gateway",
            p2pNodeUuid: gatewayInfo.uuid,
            serviceUrl: gatewayInfo.url,
            serviceName: "/person/register",
            params: {
                uuid: baseInfo.uuid,
                realName: baseInfo.realName,
                gatewayUuid: gatewayInfo.uuid,
            },
        });
        res && callback && callback(res);
        state.loading = false;
    };

    return { ...state, personGatewayRegister };
};

export default userGatewayRegister;
